package com.qinghong;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Iterator;

public class Dom4jTest {
    public static void main(String[] args) {
        SAXReader reader = new SAXReader();
        // 通过解析器的read将配置文件读取到内存中 生成一个Document[org.dom4j]对象树
        try {
            Document document = reader.read("students.xml");
            // 获取根节点
            Element root = document.getRootElement();
            // 遍历
            for (Iterator<Element> rootIter = root.elementIterator();rootIter.hasNext();){
                Element element = rootIter.next();
                for (Iterator<Element> innerIter = element.elementIterator();innerIter.hasNext();){
                    Element next = innerIter.next();
                    String innerValue = next.getStringValue();
                    System.out.println(innerValue);
                }
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
